 package ss.pku.jsa.type.inference;
 
 import org.eclipse.jdt.core.dom.ITypeBinding;

import ss.pku.jsa.type.constraint.solver.QError;
 
 public class PrimitiveQType extends QType
 {
   private static int kind = 0;
 
   public PrimitiveQType(TypeKey type, Location l, String name, boolean original) {
     setName(name);
     this.l = l;
     this.q = Qualifier.makeQualifierVariable(getName(), l, original);
     this.type = type;
   }
 
   public PrimitiveQType(ITypeBinding t, Location l, String name, boolean original) {
     this(TypeKey.getTypeKey(t), l, name, original);
     if (!t.isPrimitive())
       throw new IllegalArgumentException("Non-primitive type passed to constructor for PrimitiveQType. Argument was: " + t);
   }
 
   public QType copy(Location l, String name)
   {
     Profile.logMemStart("PrimitiveQType/copy/new PrimitiveQType");
     QType pqt = new PrimitiveQType(this.type, l, name, false);
     Profile.logMemEnd();
     return pqt;
   }
   public boolean isPrimitive() {
     return true; } 
   public int getKind() { return kind; }
 
   public String toString() {
     return getName();
   }
 
   public void setGlobal(boolean global)
   {
     this.q.setGlobal(global);
   }
 
   public void setPreferred(boolean preferred) {
     this.q.setPreferred(preferred);
   }
 
   public void merge(QType q, Location loc, QError error)
   {
     if (!(q instanceof PrimitiveQType)) {
       throw new IllegalArgumentException("Merging non-primitive QType " + q + " with " + this);
     }
     if (equals(q)) {
       return;
     }
     PrimitiveQType qt = (PrimitiveQType)q;
 
     CQual.makeEdge(Constraint.Kind.EQ, getQual(), qt.getQual(), QualGate.EMPTY, loc, 0, error);
   }
 
   public int getSize() {
     return 1;
   }
   public String toStringWithQuals(int fieldIndent) {
     String quals = this.q.getInferred();
     return quals + this.type;
   }
 }
